<!DOCTYPE html>
<html lang="en-US">
    <head>
        <title>Data::Munge - various utility functions - metacpan.org</title>
        <link rel="preload" as="fetch" href="https://metacpan.org/account/login_status" crossorigin="anonymous" />
        <link href="https://metacpan.org/_assets/b8ccceeed47a0652049703d99326a9cea4933443.css" rel="stylesheet" type="text/css">
        <script src="https://metacpan.org/_assets/6bfedafe2d7caa915b7d84f61b45936818e3242e.js" type="text/javascript" defer></script>
        <link rel="alternate" type="application/rss+xml" title="Recent CPAN Uploads of Data-Munge - MetaCPAN" href="https://metacpan.org/dist/Data-Munge/releases.rss" />
        <link rel="canonical" href="./Data::Munge.html" />
        <meta name="description" content="various utility functions" />
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=5">
        <link rel="shortcut icon" href="https://metacpan.org/static/icons/favicon.ico">
        <link rel="apple-touch-icon" sizes="152x152" href="https://metacpan.org/static/icons/apple-touch-icon.png">
        <link rel="search" href="https://metacpan.org/static/opensearch.xml" type="application/opensearchdescription+xml" title="MetaCPAN">
        <script>
          (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
          (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
          m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
          })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

          (function(skey, ga_id){
            ga('create', ga_id, {
              siteSpeedSampleRate : 100,
              storage             : 'none',
              clientId            : localStorage.getItem(skey)
            });
            ga(function(tracker) {
              localStorage.setItem(skey, tracker.get('clientId'));
            });
            ga('send', 'pageview');
          })('ga:clientId', 'UA-27829474-1');
        </script>
<meta name="twitter:card"        content="summary" />
<meta name="twitter:url"         content="https://metacpan.org/pod/Data::Munge" />
<meta name="twitter:title"       content="Data::Munge" />
<meta name="twitter:description" content="various utility functions" />
<meta name="twitter:site"        content="metacpan" />
    </head>
    <body>
        <nav class="navbar navbar-default" role="navigation">
            <div class="header-logo-large hidden-xs">
              <a href="https://metacpan.org/" tabindex="0">
                <svg class="logo" aria-label="MetaCPAN">
                  <use class="logo" href="/static/images/metacpan-logo.svg#logo" />
                </svg>
              </a>
            </div>
            <div class="header-logo-icon visible-xs">
              <a href="https://metacpan.org/">
                <svg class="logo" aria-label="MetaCPAN">
                  <use class="logo" href="/static/images/metacpan-logo.svg#dots" />
                </svg>
              </a>
            </div>
            <ul class="nav navbar-nav menu-items hidden-xs hidden-sm">
              <li><a href="https://metacpan.org/about">About</a></li>
              <li><a href="https://metacpan.org/about/sponsors">Sponsor</a></li>
              <li><a href="https://grep.metacpan.org/">grep::cpan</a></li>
              <li><a href="https://metacpan.org/recent">Recent</a></li>
              <li><a href="https://metacpan.org/about/faq">FAQ</a></li>
              <li><a href="https://metacpan.org/tools">Tools</a></li>
              <li><a href="https://fastapi.metacpan.org/">API</a></li>
            </ul>
            <ul class="nav navbar-nav navbar-right">
                <button type="button" class="searchbar-btn visible-xs visible-sm">
                    <i class="fa fa-search button-fa-icon"></i>
                </button>
                <form action="https://metacpan.org/search" class="searchbar-form visible-md visible-lg search-form form-horizontal">
                   <input type="hidden" name="size" id="metacpan_search-size" value="20">
                  <div class="form-group">
                      <div class="search-group">
                        <i class="fa fa-search"></i>
                        <input type="text" name="q" placeholder="Search the CPAN" size="41" autocorrect="off" autocapitalize="off" spellcheck="false" id="metacpan_search-input" class="form-control" value="">
                      </div>
                  </div>
                </form>
                    <li class="icon-slidepanel visible-xs visible-sm">
                      <button data-toggle="slidepanel" data-target=".slidepanel">
                        <span class="button-fa-icon">
                          <i class="fa fa-bars slidepanel-open"></i>
                          <i class="fa fa-times slidepanel-close"></i>
                        </span>
                      </button>
                    </li>
                <form action="https://metacpan.org/account/logout" method="POST" id="metacpan-logout"></form>
                <li class="dropdown logged_in" style="display: none;">
                    <button type="button" class="dropdown-toggle" data-toggle="dropdown">
                      <i class="fa fa-user button-fa-icon logged-in-icon" aria-hidden="true"></i>
                      <i class="fas fa-chevron-down"></i>
                    </button>
                    <ul class="dropdown-menu">
                        <li><a href="https://metacpan.org/account/identities">Identities</a></li>
                        <li><a href="https://metacpan.org/account/profile">Profile</a></li>
                        <li><a href="https://metacpan.org/account/favorite/list">Favorites</a></li>
                        <li>
                            <a href="./Data::Munge.html#" type="button" onclick="$('#metacpan-logout').submit(); return false">
                              Logout
                            </a>
                        </li>
                    </ul>
                </li>
                <li class="dropdown logged_out" style="display: none;">
                    <button type="button" class="dropdown-toggle" data-toggle="dropdown">
                      <i class="fa fa-user button-fa-icon" aria-hidden="true"></i>
                      <i class="fas fa-chevron-down"></i>
                    </button>
                    <ul class="dropdown-menu">
                        <li>
                            <a href="https://metacpan.org/login/github">
                                <i class="fab fa-github fa-fw"></i>
                                GitHub
                            </a>
                        </li>
                        <li>
                            <a href="https://metacpan.org/login/twitter">
                                <i class="fab fa-twitter fa-fw"></i>
                                Twitter
                            </a>
                        </li>
                        <li>
                            <a href="https://metacpan.org/login/google">
                                <i class="fab fa-google fa-fw"></i>
                                Google
                            </a>
                        </li>
                    </ul>
                </li>
                <li class="dropdown logged_placeholder">
                    <button>
                      <i class="fa fa-user button-fa-icon" aria-hidden="true"></i>
                    </button>
                </li>
            </ul>
        </nav>
        <div class="page-content ">
          <!--
          <div class="top-notify-banner">
            <i class="fas fa-info-circle"></i>
          </div>
          -->
          <nav class="sidebar">
            <div class="slidepanel">
              <ul class="nav-list ">
    <li class="nav-header no-margin-top">
      <div class="ttip" data-toggle="tooltip" data-placement="bottom" title="The date that this version of Data-Munge was released.">
      <span class="relatize">21 Mar 2023 08:38:59 UTC</span>
    </li>
  <li>
    Distribution: <a href="https://metacpan.org/dist/Data-Munge">Data-Munge</a>
  </li>
  <li>
    Module version: 0.10
  </li>
  <li>
    <a data-keyboard-shortcut="g s" href="https://metacpan.org/dist/Data-Munge/source/lib/Data/Munge.pm">Source</a>
    (<a href="https://metacpan.org/dist/Data-Munge/source/lib/Data/Munge.pm?raw=1">raw</a>)
  </li>
  <li>
    <a data-keyboard-shortcut="g b" href="https://metacpan.org/dist/Data-Munge/source/lib/Data">Browse</a>
    (<a href="https://metacpan.org/dist/Data-Munge/source/lib/Data?raw=1">raw</a>)
  </li>
    <li>
      <a data-keyboard-shortcut="g c" href="https://metacpan.org/dist/Data-Munge/changes">Changes</a>
    </li>
    <li>
      <a class="nopopup" href="https://metacpan.org/dist/Data-Munge/contribute">How to Contribute</a>
    </li>
    <li>
        <a rel="noopener nofollow" data-keyboard-shortcut="g r" href="https://github.com/mauke/Data-Munge">Repository</a>
    </li>
    <li>
      <a rel="noopener nofollow" data-keyboard-shortcut="g i" href="https://rt.cpan.org/Public/Dist/Display.html?Name=Data-Munge">Issues</a>
      (0)
    </li>
    <li>
      <a rel="noopener nofollow" href="http://matrix.cpantesters.org/?dist=Data-Munge+0.10" title="Matrix">Testers</a>
        <span title="(pass / fail / na)">(<a rel="noopener nofollow" href="https://www.cpantesters.org/distro/D/Data-Munge.html?oncpan=1&amp;distmat=1&amp;version=0.10&amp;grade=2" style="color: #090">1487</a> / <a rel="noopener nofollow" href="https://www.cpantesters.org/distro/D/Data-Munge.html?oncpan=1&amp;distmat=1&amp;version=0.10&amp;grade=3" style="color: #900">0</a> / <a rel="noopener nofollow" href="https://www.cpantesters.org/distro/D/Data-Munge.html?oncpan=1&amp;distmat=1&amp;version=0.10&amp;grade=4">0</a>)</span>
    </li>
    <li>
      <a rel="noopener nofollow" href="http://cpants.cpanauthors.org/release/MAUKE/Data-Munge-0.10">Kwalitee</a>
    </li>
    <li>
      <div class="ttip" data-toggle="tooltip" data-placement="bottom" title="The # people with an indexing permission on Data-Munge who have released something to CPAN in the last 2 years (i.e. the # people likely able to release critical fixes in a timely manner)">
      Bus factor: 1
      </div>
    </li>
    <li>
      <a rel="noopener nofollow" href="http://cpancover.com/latest/Data-Munge-0.10/index.html">94.37% Coverage </a>
    </li>
    <li>
      License: perl_5
    </li>
    <li class="nav-header">Activity</li>
    <li>
<div class="activity-graph">
    <img src="https://metacpan.org/dist/Data-Munge/activity.svg?res=month" />
    <div class="comment">24 month</div>
</div>
    </li>
    <li class="nav-header">Tools</li>
    <li>
      <a itemprop="downloadUrl" href="https://cpan.metacpan.org/authors/id/M/MA/MAUKE/Data-Munge-0.10.tar.gz">
      Download (<span itemprop="fileSize">9.43KB</span>)</a>
    </li>
    <li>
      <a href="https://explorer.metacpan.org/?url=%2Fmodule%2FMAUKE%2FData-Munge-0.10%2Flib%2FData%2FMunge.pm">
        MetaCPAN Explorer
      </a>
    </li>
    <li>
      <a href="https://metacpan.org/dist/Data-Munge/permissions">
        Permissions
      </a>
    </li>
    <li>
      <a href="https://metacpan.org/dist/Data-Munge/releases.rss">
        Subscribe to distribution
      </a>
    </li>
    <li>
      <button class="btn btn-link" data-toggle="modal" data-target="#metacpan_install-instructions-dialog">
        Install Instructions
      </button>
    </li>
    <li>
      <form action="https://metacpan.org/search">
        <input type="hidden" name="q" value="dist:Data-Munge">
        <input type="search" name="q" placeholder="Search distribution" class="form-control tool-bar-form">
        <input type="submit" style="display: none">
      </form>
    </li>
    <li>
      <form action="https://grep.metacpan.org/search">
        <input type="hidden" name="qd" value="Data-Munge">
        <input type="hidden" name="source" value="metacpan">
        <input type="search" name="q" placeholder="grep distribution" class="form-control tool-bar-form">
        <input type="submit" style="display: none">
     </form>
    </li>
    <li class="version-jump">
<select onchange="document.location.href=&#39;/release/&#39;+this.value+&#39;/view/lib/Data/Munge.pm&#39;" class="form-control tool-bar-form">
  <option disabled selected>Jump to version</option>
<option
  disabled
  value="MAUKE/Data-Munge-0.10"
>0.10
  (MAUKE on 2023-03-21)</option>
<option
  
  value="MAUKE/Data-Munge-0.097"
>0.097
  (MAUKE on 2017-03-17)</option>
<optgroup label="BackPAN">'
<option
  
  value="MAUKE/Data-Munge-0.096"
>0.096
  (MAUKE on 2016-03-02)</option>
<option
  
  value="MAUKE/Data-Munge-0.095"
>0.095
  (MAUKE on 2015-05-08)</option>
<option
  
  value="MAUKE/Data-Munge-0.094"
>0.094
  (MAUKE on 2015-03-08)</option>
<option
  
  value="MAUKE/Data-Munge-0.093"
>0.093
  (MAUKE on 2014-12-23)</option>
<option
  
  value="MAUKE/Data-Munge-0.092"
>0.092
  (MAUKE on 2014-11-25)</option>
<option
  
  value="MAUKE/Data-Munge-0.091"
>0.091
  (MAUKE on 2014-11-19)</option>
<option
  
  value="MAUKE/Data-Munge-0.09"
>0.09
  (MAUKE on 2014-11-18)</option>
<option
  
  value="MAUKE/Data-Munge-0.08"
>0.08
  (MAUKE on 2014-09-15)</option>
<option
  
  value="MAUKE/Data-Munge-0.07"
>0.07
  (MAUKE on 2013-10-22)</option>
<option
  
  value="MAUKE/Data-Munge-0.06"
>0.06
  (MAUKE on 2013-03-07)</option>
<option
  
  value="MAUKE/Data-Munge-0.05"
>0.05
  (MAUKE on 2013-03-05)</option>
<option
  
  value="MAUKE/Data-Munge-0.04"
>0.04
  (MAUKE on 2011-08-03)</option>
<option
  
  value="MAUKE/Data-Munge-0.032"
>0.032
  (MAUKE on 2010-01-23)</option>
<option
  
  value="MAUKE/Data-Munge-0.031"
>0.031
  (MAUKE on 2010-01-20)</option>
<option
  
  value="MAUKE/Data-Munge-0.03"
>0.03
  (MAUKE on 2010-01-19)</option>
<option
  
  value="MAUKE/Data-Munge-0.02"
>0.02
  (MAUKE on 2009-12-14)</option>
</optgroup>
</select>
    </li>
    <li class="version-diff">
<select onchange="document.location.href='/release/MAUKE/Data-Munge-0.10/diff/' + encodeURIComponent(this.value) + '/lib/Data/Munge.pm'
" class="form-control tool-bar-form">
  <option disabled selected>Diff with version</option>
<option
  disabled
  value="MAUKE/Data-Munge-0.10"
>0.10
  (MAUKE on 2023-03-21)</option>
<option
  
  value="MAUKE/Data-Munge-0.097"
>0.097
  (MAUKE on 2017-03-17)</option>
<optgroup label="BackPAN">'
<option
  
  value="MAUKE/Data-Munge-0.096"
>0.096
  (MAUKE on 2016-03-02)</option>
<option
  
  value="MAUKE/Data-Munge-0.095"
>0.095
  (MAUKE on 2015-05-08)</option>
<option
  
  value="MAUKE/Data-Munge-0.094"
>0.094
  (MAUKE on 2015-03-08)</option>
<option
  
  value="MAUKE/Data-Munge-0.093"
>0.093
  (MAUKE on 2014-12-23)</option>
<option
  
  value="MAUKE/Data-Munge-0.092"
>0.092
  (MAUKE on 2014-11-25)</option>
<option
  
  value="MAUKE/Data-Munge-0.091"
>0.091
  (MAUKE on 2014-11-19)</option>
<option
  
  value="MAUKE/Data-Munge-0.09"
>0.09
  (MAUKE on 2014-11-18)</option>
<option
  
  value="MAUKE/Data-Munge-0.08"
>0.08
  (MAUKE on 2014-09-15)</option>
<option
  
  value="MAUKE/Data-Munge-0.07"
>0.07
  (MAUKE on 2013-10-22)</option>
<option
  
  value="MAUKE/Data-Munge-0.06"
>0.06
  (MAUKE on 2013-03-07)</option>
<option
  
  value="MAUKE/Data-Munge-0.05"
>0.05
  (MAUKE on 2013-03-05)</option>
<option
  
  value="MAUKE/Data-Munge-0.04"
>0.04
  (MAUKE on 2011-08-03)</option>
<option
  
  value="MAUKE/Data-Munge-0.032"
>0.032
  (MAUKE on 2010-01-23)</option>
<option
  
  value="MAUKE/Data-Munge-0.031"
>0.031
  (MAUKE on 2010-01-20)</option>
<option
  
  value="MAUKE/Data-Munge-0.03"
>0.03
  (MAUKE on 2010-01-19)</option>
<option
  
  value="MAUKE/Data-Munge-0.02"
>0.02
  (MAUKE on 2009-12-14)</option>
</optgroup>
</select>
    </li>

    <li>
<ul class="dependencies">
  <li class="nav-header">Dependencies</li>
  <li><a href="https://metacpan.org/pod/Exporter" title="Exporter" class="ellipsis">Exporter</a></li>
  <li><a href="https://metacpan.org/pod/strict" title="strict" class="ellipsis">strict</a></li>
  <li><a href="https://metacpan.org/pod/warnings" title="warnings" class="ellipsis">warnings</a></li>
  <li>
    <hr>
  </li>
  <li>
    <a href="https://metacpan.org/module/Data::Munge/requires">Reverse dependencies</a>
  </li>
  <li>
    <a href="http://deps.cpantesters.org/?module=Data%3A%3AMunge">CPAN Testers List</a>
  </li>
  <li>
    <a href="https://cpandeps.grinnz.com/?dist=Data-Munge">Dependency graph</a>
  </li>
</ul>
    </li>
    <li class="nav-header">Permalinks</li>
    <li>
      <a href="https://metacpan.org/release/MAUKE/Data-Munge-0.10/view/lib/Data/Munge.pm">This version</a>
    </li>
    <li>
      <a href="./Data::Munge.html">Latest version</a>
    </li>
    <li>
<div class="plussers">
<div class="nav-header">++ed by:</div>
<div>
<a class="display-all" href="https://metacpan.org/author/EGOR"><img src="https://www.gravatar.com/avatar/d1b2873e176897abb1f26be3a92e771d?d=identicon&amp;s=20" title="EGOR" alt="EGOR"></a>
<a class="display-all" href="https://metacpan.org/author/DRAEGTUN"><img src="https://www.gravatar.com/avatar/6f1ae19bf6507a7bd1ea0d0f6abfeb01?d=identicon&amp;s=20" title="DRAEGTUN" alt="DRAEGTUN"></a>
<a class="display-all" href="https://metacpan.org/author/SHLOMIF"><img src="https://www.gravatar.com/avatar/072331b92b0e6e9d9bc31c3af8f8ccea?d=identicon&amp;s=20" title="SHLOMIF" alt="SHLOMIF"></a>
</div>
<!-- Display counts of plussers-->
<div>
    <a href="https://metacpan.org/dist/Data-Munge/plussers">3 PAUSE users</a>
</div>
<div>
    4 non-PAUSE users
</div>
</div>
    </li>
    <li>
<div id="metacpan_contributors">
  <div>
    <button class="btn-link"
      onclick="$(this).hide(); $('#metacpan_contributors ul').slideDown(); return false;"
    >and 1 contributors</button>
  </div>
  <ul style="display: none">
    <li class="contributor"
      data-contrib-email="l.mai@web.de"
    >
      <img class="gravatar" width="20" height="20" src="https://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?d=identicon&amp;s=20" />
      Lukas Mai
    </li>
  </ul>
</div>
    </li>
              </ul>
            </div>
          </nav>
          <div class="content-navigation">
<div class="breadcrumbs">
  <span>
    <a data-keyboard-shortcut="g a" rel="author" href="https://metacpan.org/author/MAUKE" class="author-name">Lukas Mai</a>
  </span>
  <span>&nbsp;/&nbsp;</span>
  <div class="release dist-release status-latest maturity-released">
    <span class="dropdown"><b class="caret"></b></span>
<select onchange="document.location.href=&#39;/release/&#39;+this.value+&#39;/view/lib/Data/Munge.pm&#39;" class="">
<option
  selected
  value="MAUKE/Data-Munge-0.10"
>0.10
  (MAUKE on 2023-03-21)</option>
<option
  
  value="MAUKE/Data-Munge-0.097"
>0.097
  (MAUKE on 2017-03-17)</option>
<optgroup label="BackPAN">'
<option
  
  value="MAUKE/Data-Munge-0.096"
>0.096
  (MAUKE on 2016-03-02)</option>
<option
  
  value="MAUKE/Data-Munge-0.095"
>0.095
  (MAUKE on 2015-05-08)</option>
<option
  
  value="MAUKE/Data-Munge-0.094"
>0.094
  (MAUKE on 2015-03-08)</option>
<option
  
  value="MAUKE/Data-Munge-0.093"
>0.093
  (MAUKE on 2014-12-23)</option>
<option
  
  value="MAUKE/Data-Munge-0.092"
>0.092
  (MAUKE on 2014-11-25)</option>
<option
  
  value="MAUKE/Data-Munge-0.091"
>0.091
  (MAUKE on 2014-11-19)</option>
<option
  
  value="MAUKE/Data-Munge-0.09"
>0.09
  (MAUKE on 2014-11-18)</option>
<option
  
  value="MAUKE/Data-Munge-0.08"
>0.08
  (MAUKE on 2014-09-15)</option>
<option
  
  value="MAUKE/Data-Munge-0.07"
>0.07
  (MAUKE on 2013-10-22)</option>
<option
  
  value="MAUKE/Data-Munge-0.06"
>0.06
  (MAUKE on 2013-03-07)</option>
<option
  
  value="MAUKE/Data-Munge-0.05"
>0.05
  (MAUKE on 2013-03-05)</option>
<option
  
  value="MAUKE/Data-Munge-0.04"
>0.04
  (MAUKE on 2011-08-03)</option>
<option
  
  value="MAUKE/Data-Munge-0.032"
>0.032
  (MAUKE on 2010-01-23)</option>
<option
  
  value="MAUKE/Data-Munge-0.031"
>0.031
  (MAUKE on 2010-01-20)</option>
<option
  
  value="MAUKE/Data-Munge-0.03"
>0.03
  (MAUKE on 2010-01-19)</option>
<option
  
  value="MAUKE/Data-Munge-0.02"
>0.02
  (MAUKE on 2009-12-14)</option>
</optgroup>
</select>
    <a data-keyboard-shortcut="g d" class="release-name" href="https://metacpan.org/dist/Data-Munge">Data-Munge-0.10</a>
  </div>
<span class="river-gauge-gauge">
  <svg width="24px"
       height="15px"
       version="1.1"
       xmlns="http://www.w3.org/2000/svg"
       xmlns:xlink="http://www.w3.org/1999/xlink">

    <g>
      <title>        River stage two &#10;
          • 12 direct dependents &#10;          • 16 total dependents
      </title>

      <rect x="0"  y="0" width="4" height="15" fill="#7ea3f2" />
      <rect x="5"  y="0" width="4" height="15" fill="#7ea3f2" />
      <rect x="10"  y="0" width="4" height="15" fill="#e4e2e2" />
      <rect x="15"  y="0" width="4" height="15" fill="#e4e2e2" />
      <rect x="20"  y="0" width="4" height="15" fill="#e4e2e2" />
    </g>
  </svg>

</span>
<div id="Data-Munge-fav" class="logged_in">
<form action="https://metacpan.org/account/favorite/add" style="display: inline" onsubmit="return favDistribution(this)">
    <input type="hidden" name="remove" value="0">
    <input type="hidden" name="release" value="Data-Munge-0.10">
    <input type="hidden" name="author" value="MAUKE">
    <input type="hidden" name="distribution" value="Data-Munge">
    <button type="submit" class="favorite highlight"><span>7</span> ++</button>
</form>
</div>
<div class="logged_out">
<a href="./Data::Munge.html" onclick="alert('Please sign in to add favorites'); return false" class="favorite highlight">
<span>7</span> ++</a>
</div>
   / <span>Data::Munge</span>
</div>
          </div>
          <main class="content">


<nav class="toc">
  <div class="toc-header"><strong>Contents</strong></div>
<ul>
  <li><a href="./Data::Munge.html#NAME">NAME</a></li>
  <li><a href="./Data::Munge.html#SYNOPSIS">SYNOPSIS</a></li>
  <li><a href="./Data::Munge.html#DESCRIPTION">DESCRIPTION</a>
    <ul>
      <li><a href="./Data::Munge.html#Functions">Functions</a></li>
    </ul>
  </li>
  <li><a href="./Data::Munge.html#AUTHOR">AUTHOR</a></li>
  <li><a href="./Data::Munge.html#COPYRIGHT-&amp;-LICENSE">COPYRIGHT &amp; LICENSE</a></li>
</ul></nav>
<div class="pod anchors">
<h1 id="NAME">NAME</h1>

<p>Data::Munge - various utility functions</p>

<h1 id="SYNOPSIS">SYNOPSIS</h1>

<pre><code>    use Data::Munge;

    my $re = list2re qw/f ba foo bar baz/;
    # $re = qr/bar|baz|foo|ba|f/;

    print byval { s/foo/bar/ } $text;
    # print do { my $tmp = $text; $tmp =~ s/foo/bar/; $tmp };

    foo(mapval { chomp } @lines);
    # foo(map { my $tmp = $_; chomp $tmp; $tmp } @lines);

    print replace(&#39;Apples are round, and apples are juicy.&#39;, qr/apples/i, &#39;oranges&#39;, &#39;g&#39;);
    # &quot;oranges are round, and oranges are juicy.&quot;
    print replace(&#39;John Smith&#39;, qr/(\w+)\s+(\w+)/, &#39;$2, $1&#39;);
    # &quot;Smith, John&quot;

    my $trimmed = trim &quot;  a b c &quot;;
    # &quot;a b c&quot;

    my $x = &#39;bar&#39;;
    if (elem $x, [qw(foo bar baz)]) { ... }
    # executes: $x is an element of the arrayref

    my $contents = slurp $fh;  # or: slurp *STDIN
    # reads all data from a filehandle into a scalar

    eval_string(&#39;print &quot;hello world\\n&quot;&#39;);  # says hello
    eval_string(&#39;die&#39;);  # dies
    eval_string(&#39;{&#39;);    # throws a syntax error

    my $fac = rec {
      my ($rec, $n) = @_;
      $n &lt; 2 ? 1 : $n * $rec-&gt;($n - 1)
    };
    print $fac-&gt;(5);  # 120

    if (&quot;hello, world!&quot; =~ /(\w+), (\w+)/) {
      my @captured = submatches;
      # @captured = (&quot;hello&quot;, &quot;world&quot;)
    }</code></pre>

<h1 id="DESCRIPTION">DESCRIPTION</h1>

<p>This module defines a few generally useful utility functions. I got tired of redefining or working around them, so I wrote this module.</p>

<h2 id="Functions">Functions</h2>

<dl>

<dt id="list2re-LIST"><a id="list2re"></a>list2re LIST</dt>
<dd>

<p>Converts a list of strings to a regex that matches any of the strings. Especially useful in combination with <code>keys</code>. Example:</p>

<pre><code>    my $re = list2re keys %hash;
    $str =~ s/($re)/$hash{$1}/g;</code></pre>

<p>This function takes special care to get several edge cases right:</p>

<ul>

<li><p>Empty list: An empty argument list results in a regex that doesn&#39;t match anything.</p>

</li>
<li><p>Empty string: An argument list consisting of a single empty string results in a regex that matches the empty string (and nothing else).</p>

</li>
<li><p>Prefixes: The input strings are sorted by descending length to ensure longer matches are tried before shorter matches. Otherwise <code>list2re(&#39;ab&#39;, &#39;abcd&#39;)</code> would generate <code>qr/ab|abcd/</code>, which (on its own) can never match <code>abcd</code> (because <code>ab</code> is tried first, and it always succeeds where <code>abcd</code> could).</p>

</li>
</ul>

</dd>
<dt id="byval-BLOCK-SCALAR"><a id="byval"></a>byval BLOCK SCALAR</dt>
<dd>

<p>Takes a code block and a value, runs the block with <code>$_</code> set to that value, and returns the final value of <code>$_</code>. The global value of <code>$_</code> is not affected. <code>$_</code> isn&#39;t aliased to the input value either, so modifying <code>$_</code> in the block will not affect the passed in value. Example:</p>

<pre><code>    foo(byval { s/!/?/g } $str);
    # Calls foo() with the value of $str, but all &#39;!&#39; have been replaced by &#39;?&#39;.
    # $str itself is not modified.</code></pre>

<p>Since perl 5.14 you can also use the <code>/r</code> flag:</p>

<pre><code>    foo($str =~ s/!/?/gr);</code></pre>

<p>But <code>byval</code> works on all versions of perl and is not limited to <code>s///</code>.</p>

</dd>
<dt id="mapval-BLOCK-LIST"><a id="mapval"></a>mapval BLOCK LIST</dt>
<dd>

<p>Works like a combination of <code>map</code> and <code>byval</code>; i.e. it behaves like <code>map</code>, but <code>$_</code> is a copy, not aliased to the current element, and the return value is taken from <code>$_</code> again (it ignores the value returned by the block). Example:</p>

<pre><code>    my @foo = mapval { chomp } @bar;
    # @foo contains a copy of @bar where all elements have been chomp&#39;d.
    # This could also be written as chomp(my @foo = @bar); but that&#39;s not
    # always possible.</code></pre>

</dd>
<dt id="submatches">submatches</dt>
<dd>

<p>Returns a list of the strings captured by the last successful pattern match. Normally you don&#39;t need this function because this is exactly what <code>m//</code> returns in list context. However, <code>submatches</code> also works in other contexts such as the RHS of <code>s//.../e</code>.</p>

</dd>
<dt id="replace-STRING,-REGEX,-REPLACEMENT,-FLAG"><a id="replace"></a><a id="replace-STRING--REGEX--REPLACEMENT--FLAG"></a>replace STRING, REGEX, REPLACEMENT, FLAG</dt>
<dd>

</dd>
<dt id="replace-STRING,-REGEX,-REPLACEMENT"><a id="replace1"></a><a id="replace-STRING--REGEX--REPLACEMENT"></a>replace STRING, REGEX, REPLACEMENT</dt>
<dd>

<p>A clone of javascript&#39;s <code>String.prototype.replace</code>. It works almost the same as <code>byval { s/REGEX/REPLACEMENT/FLAG } STRING</code>, but with a few important differences. REGEX can be a string or a compiled <code>qr//</code> object. REPLACEMENT can be a string or a subroutine reference. If it&#39;s a string, it can contain the following replacement patterns:</p>

<dl>

<dt id="$$"><a id="pod"></a>$$</dt>
<dd>

<p>Inserts a &#39;$&#39;.</p>

</dd>
<dt id="$&amp;"><a id="pod1"></a>$&amp;</dt>
<dd>

<p>Inserts the matched substring.</p>

</dd>
<dt id="$`"><a id="pod2"></a>$`</dt>
<dd>

<p>Inserts the substring preceding the match.</p>

</dd>
<dt id="$&#39;"><a id="pod3"></a>$&#39;</dt>
<dd>

<p>Inserts the substring following the match.</p>

</dd>
<dt id="$N-(where-N-is-a-digit)"><a id="N--where-N-is-a-digit"></a>$N (where N is a digit)</dt>
<dd>

<p>Inserts the substring matched by the Nth capturing group.</p>

</dd>
<dt id="${N}-(where-N-is-one-or-more-digits)"><a id="N---where-N-is-one-or-more-digits"></a>${N} (where N is one or more digits)</dt>
<dd>

<p>Inserts the substring matched by the Nth capturing group.</p>

</dd>
</dl>

<p>Note that these aren&#39;t variables; they&#39;re character sequences interpreted by <code>replace</code>.</p>

<p>If REPLACEMENT is a subroutine reference, it&#39;s called with the following arguments: First the matched substring (like <code>$&amp;</code> above), then the contents of the capture buffers (as returned by <code>submatches</code>), then the offset where the pattern matched (like <code>$-[0]</code>, see <a href="variables/$&lt;digits&gt;-($1,-$2,-...).html#@-">&quot;@-&quot; in perlvar</a>), then the STRING. The return value will be inserted in place of the matched substring.</p>

<p>Normally only the first occurrence of REGEX is replaced. If FLAG is present, it must be <code>&#39;g&#39;</code> and causes all occurrences to be replaced.</p>

</dd>
<dt id="trim-STRING"><a id="trim"></a>trim STRING</dt>
<dd>

<p>Returns <i>STRING</i> with all leading and trailing whitespace removed. Like <a href="functions/CORE.html#length-EXPR"><code>length</code></a> it returns <code>undef</code> if the input is <code>undef</code>.</p>

</dd>
<dt id="elem-SCALAR,-ARRAYREF"><a id="elem"></a><a id="elem-SCALAR--ARRAYREF"></a>elem SCALAR, ARRAYREF</dt>
<dd>

<p>Returns a boolean value telling you whether <i>SCALAR</i> is an element of <i>ARRAYREF</i> or not. Two scalars are considered equal if they&#39;re both <code>undef</code>, if they&#39;re both references to the same thing, or if they&#39;re both not references and <code>eq</code> to each other.</p>

<p>This is implemented as a linear search through <i>ARRAYREF</i> that terminates early if a match is found (i.e. <code>elem &#39;A&#39;, [&#39;A&#39;, 1 .. 9999]</code> won&#39;t even look at elements <code>1 .. 9999</code>).</p>

</dd>
<dt id="eval_string-STRING"><a id="eval_string"></a>eval_string STRING</dt>
<dd>

<p>Evals <i>STRING</i> just like <code>eval</code> but doesn&#39;t catch exceptions. Caveat: Unlike with <code>eval</code> the code runs in an empty lexical scope:</p>

<pre><code>    my $foo = &quot;Hello, world!\n&quot;;
    eval_string &#39;print $foo&#39;;
    # Dies: Global symbol &quot;$foo&quot; requires explicit package name</code></pre>

<p>That is, the eval&#39;d code can&#39;t see variables from the scope of the <code>eval_string</code> call.</p>

</dd>
<dt id="slurp-FILEHANDLE"><a id="slurp"></a>slurp FILEHANDLE</dt>
<dd>

<p>Reads and returns all remaining data from <i>FILEHANDLE</i> as a string, or <code>undef</code> if it hits end-of-file. (Interaction with non-blocking filehandles is currently not well defined.)</p>

<p><code>slurp $handle</code> is equivalent to <code>do { local $/; scalar readline $handle }</code>.</p>

</dd>
<dt id="rec-BLOCK"><a id="rec"></a>rec BLOCK</dt>
<dd>

<p>Creates an anonymous sub as <code>sub BLOCK</code> would, but supplies the called sub with an extra argument that can be used to recurse:</p>

<pre><code>    my $code = rec {
      my ($rec, $n) = @_;
      $rec-&gt;($n - 1) if $n &gt; 0;
      print $n, &quot;\n&quot;;
    };
    $code-&gt;(4);</code></pre>

<p>That is, when the sub is called, an implicit first argument is passed in <code>$_[0]</code> (all normal arguments are moved one up). This first argument is a reference to the sub itself. This reference could be used to recurse directly or to register the sub as a handler in an event system, for example.</p>

<p>A note on defining recursive anonymous functions: Doing this right is more complicated than it may at first appear. The most straightforward solution using a lexical variable and a closure leaks memory because it creates a reference cycle. Starting with perl 5.16 there is a <code>__SUB__</code> constant that is equivalent to <code>$rec</code> above, and this is indeed what this module uses (if available).</p>

<p>However, this module works even on older perls by falling back to either weak references (if available) or a &quot;fake recursion&quot; scheme that dynamically instantiates a new sub for each call instead of creating a cycle. This last resort is slower than weak references but works everywhere.</p>

</dd>
</dl>

<h1 id="AUTHOR">AUTHOR</h1>

<p>Lukas Mai, <code>&lt;l.mai at web.de&gt;</code></p>

<h1 id="COPYRIGHT-&amp;-LICENSE"><a id="COPYRIGHT"></a><a id="COPYRIGHT---LICENSE"></a>COPYRIGHT &amp; LICENSE</h1>

<p>Copyright 2009-2011, 2013-2015, 2023 Lukas Mai.</p>

<p>This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.</p>

<p>See <a href="https://dev.perl.org/licenses/">https://dev.perl.org/licenses/</a> for more information.</p></div>

<div id="metacpan_install-instructions-dialog" class="modal fade">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title">Module Install Instructions</h4>
      </div>
      <div class="modal-body">
        <p>To install Data::Munge, copy and paste the appropriate command in to your terminal.</p>
        <p><a href="https://metacpan.org/dist/App-cpanminus/view/bin/cpanm">cpanm</a></p>
        <pre><code>cpanm Data::Munge</code></pre>
        <p><a href="https://metacpan.org/pod/CPAN">CPAN shell</a></p>
        <pre><code>perl -MCPAN -e shell
install Data::Munge</code></pre>
        <p>For more information on module installation, please visit <a href="https://www.cpan.org/modules/INSTALL.html">the detailed CPAN module installation guide</a>.</p>
      </div>
      <div class="modal-footer">
        <a href="./Data::Munge.html#" data-dismiss="modal" class="btn">Close</a>
      </div>
    </div>
  </div>
</div>
          </main>
          <div class="content-pagination">
          </div>
        </div>
        <footer class="footer">
          <div class="footer-container">
            <div class="footer-social">
              <div class="footer-link footer-logo">
                <a href="https://metacpan.org/">
                  <img src="https://metacpan.org/static/images/metacpan-logo.svg" alt="MetaCPAN" />
                </a>
              </div>
              <a class="footer-social-link" href="https://github.com/metacpan">
                <i class="fab fa-github-square"></i>
              </a>
              <a class="footer-social-link" href="https://fosstodon.org/@metacpan">
                <i class="fab fa-mastodon"></i>
              </a>
            </div>
            <div class="footer-links">
              <div class="footer-link">
                  <a href="https://metacpan.org/about">About</a>
              </div>
              <div class="footer-link">
                  <a href="https://metacpan.org/about/sponsors">Sponsor</a>
              </div>
              <div class="footer-link">
                  <a href="https://grep.metacpan.org">grep::cpan</a>
              </div>
              <div class="footer-link">
                  <a href="https://metacpan.org/recent">Recent</a>
              </div>
              <div class="footer-link">
                  <a href="https://metacpan.org/about/faq">FAQ</a>
              </div>
              <div class="footer-link">
                  <a href="https://metacpan.org/tools">Tools</a>
              </div>
              <div class="footer-link">
                  <a href="https://fastapi.metacpan.org/">API</a>
              </div>
              <div class="footer-link">
                  <a href="https://www.perl.org/">Perl.org</a>
              </div>
            </div>
            <div class="footer-sponsors">
              <a class="footer-sponsor-link" target="_blank" href="https://www.bytemark.co.uk/" rel="noopener">
                <img class="footer-sponsor-bytemark" src="https://metacpan.org/static/images/sponsors/bytemark_logo.svg" alt="Bytemark logo">
              </a>
              <a class="footer-sponsor-link" target="_blank" href="https://www.liquidweb.com/" rel="noopener">
                <img class="footer-sponsor-liquidweb" src="https://metacpan.org/static/images/sponsors/liquidweb_logo.png" alt="liquidweb logo">
              </a>
              <a class="footer-sponsor-link" target="_blank" href="https://deriv.com/careers/" rel="noopener">
                <img class="footer-sponsor-deriv" src="https://metacpan.org/static/images/sponsors/deriv.svg" alt="Deriv logo">
              </a>
              <a class="footer-sponsor-link" target="_blank" href="https://geocode.xyz" rel="noopener">
                <img class="footer-sponsor-geocode" src="https://metacpan.org/static/images/sponsors/geocodelogo.svg" alt="Geocode logo">
              </a>
              <a class="footer-sponsor-link" target="_blank" href="https://www.fastly.com/" rel="noopener">
                <img class="footer-sponsor-fastly" src="https://metacpan.org/static/images/sponsors/fastly_logo.svg" alt="Fastly logo">
              </a>
              <a class="footer-sponsor-link" target="_blank" href="https://opencagedata.com" rel="noopener">
                <img class="footer-sponsor-opencage" src="https://metacpan.org/static/images/sponsors/open-cage.svg" alt="OpenCage logo">
              </a>
            </div>
          </div>
        </footer>
        <div class="modal fade" tabindex="-1" role="dialog" id="metacpan_keyboard-shortcuts">
          <div class="modal-dialog">
            <div class="modal-content">
              <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title">Keyboard Shortcuts</h4>
              </div>
              <div class="modal-body row">
<div class="col-md-6">
  <table class="table keyboard-shortcuts">
    <thead>
      <tr>
        <th></th>
        <th>Global</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td class="keys">
          <kbd>s</kbd>
        </td>
        <td>Focus search bar</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>?</kbd>
        </td>
        <td>Bring up this help dialog</td>
      </tr>
    </tbody>
  </table>

  <table class="table keyboard-shortcuts">
    <thead>
      <tr>
        <th></th>
        <th>GitHub</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>p</kbd>
        </td>
        <td>Go to pull requests</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>i</kbd>
        </td>
        <td>go to github issues (only if github is preferred repository)</td>
      </tr>
    </tbody>
  </table>
</div>

<div class="col-md-6">
  <table class="table keyboard-shortcuts">
    <thead>
      <tr>
        <th></th>
        <th>POD</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>a</kbd>
        </td>
        <td>Go to author</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>c</kbd>
        </td>
        <td>Go to changes</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>i</kbd>
        </td>
        <td>Go to issues</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>d</kbd>
        </td>
        <td>Go to dist</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>r</kbd>
        </td>
        <td>Go to repository/SCM</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>s</kbd>
        </td>
        <td>Go to source</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>b</kbd>
        </td>
        <td>Go to file browse</td>
      </tr>

    </tbody>
  </table>
</div>

<div class="col-md-12">
  <table class="table keyboard-shortcuts">
    <thead>
      <tr>
        <th></th>
        <th>Search terms</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td><em>module:</em> (e.g. <a href="https://metacpan.org/search?q=module%3APlugin">module:Plugin</a>)</td>
      </tr>
      <tr>
        <td><em>distribution:</em> (e.g. <a href="https://metacpan.org/search?q=distribution%3ADancer+auth">distribution:Dancer auth</a>)</td>
      </tr>
      <tr>
        <td><em>author:</em> (e.g. <a href="https://metacpan.org/search?q=author%3ASONGMU+Redis">author:SONGMU Redis</a>)</td>
      </tr>
      <tr>
        <td><em>version:</em> (e.g. <a href="https://metacpan.org/search?q=version%3A1.00">version:1.00</a>)</td>
      </tr>
    </tbody>
  </table>
</div>
              </div>
              <div class="modal-footer"></div>
            </div>
          </div>
        </div>
    </body>
</html>
